//
//  DateExtensions.swift
//  SwiftWeather
//
//  Created by shen on 2023/8/28.
//

import Foundation

enum DateFormat: String {
    case dailyWeatherForecast = "yyyy-MM-dd"
    case hourlyWeatherForecast = "yyyy-MM-dd HH:mm"
    case weekday = "EEEE"
    case hour = "h a"
}

extension String {
    func convertToDate(format: String) -> Date? {
        sf.date(with: format)
    }
}

extension Date {
    func toString(format: String) -> String {
        sf.string(with: format)
    }

    func convertToWeekday() -> String {
        toString(format: DateFormat.weekday.rawValue)
    }
}

extension Calendar {
    func minutes(from startDate: Date, to endDate: Date) -> Int? {
        return self.dateComponents([.minute], from: startDate, to: endDate).minute
    }
}
